import React, {Component} from "react";

import PropTypes from 'prop-types';




export default class RItem extends Component{
    constructor(props) {
        super(props);
        this.itemClick = this.itemClick.bind(this);  //使用这种更利于后期的性能优化
    }


    //性能优化可以使用的周期
    shouldComponentUpdate(nextProps, nextState, nextContext) {
        if(nextProps.content === this.props.content){
            return false
        }
        return true

    }

    itemClick(){
        console.log(1)
        this.props.delItem(this.props.index)
    }

    render() {
        return (
            <li onClick={this.itemClick}>{this.props.user} - {this.props.item}</li>
        )
    }

}

//校验传递的值
RItem.propTypes = {
    item: PropTypes.string,
    user: PropTypes.string.isRequired //必须传
}